package sqlanalysisgui.editor;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;

import com.cho.core.db.dao.TableDao;
import com.cho.core.vo.TableVo;

import sqlanalysisgui.editor.scanner.DataBaseSyntaxLineStyler;
import sqlanalysisgui.session.SessionInfo;
import sqlanalysisgui.view.model.TableInfo;

public class SqlSourceEditor extends AbstractDecoratedTextEditor {
	private Logger logger =  Logger.getLogger(this.getClass());
	public static final String ID = "sqlanalysisgui.editor.sqlSourceEditor"; //$NON-NLS-1$
	private String fileSeq;
	public Composite parent;
	public StyledText styledText ;
	private List<Map<String, String>> tableInfos;
	
	@Override
	public void createPartControl(Composite parent) {
		// CHO Auto-generated method stub
		super.createPartControl(parent);
		this.parent = parent;
//		LineNumberRulerColumn lineNumberRulerColumn = (LineNumberRulerColumn) createLineNumberRulerColumn();
//		handleCursorPositionChanged();
//		
		//setHighlightRange
		//styledText
		//ITextEditor
/*
		 if (isPrefQuickDiffAlwaysOn()) {
             LineNumberChangeRulerColumn column= new LineNumberChangeRulerColumn(getSharedColors());
             column.setHover(createChangeHover());
             initializeChangeRulerColumn(column);
             fLineNumberRulerColumn= column;
       } else {
             fLineNumberRulerColumn= new LineNumberRulerColumn();
       }*/
		
		//this.getEditorSite().getShell().
		
		setStyledText(this.getSourceViewer().getTextWidget());
		
		StyledText styledText = getStyledText();
		//styledText.setLineBackground(1, 5,parent.getShell().getDisplay(). getSystemColor(SWT.COLOR_BLUE));// new Color(parent.getDisplay(), 255, 127, 0));
		styledText.setFont(new Font(styledText.getDisplay(), "굴림체", 12, SWT.NORMAL));
		logger.debug("styledText: " + styledText);
		styledText.addLineStyleListener(new DataBaseSyntaxLineStyler(tableInfos));
		
		/*
		 * 
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
    // make 0123456789 appear bold
    StyleRange style1 = new StyleRange();
    style1.start = 0;
    style1.length = 10;
    style1.fontStyle = SWT.BOLD;
    text.setStyleRange(style1);
    // make ABCDEFGHIJKLM have a red font
    StyleRange style2 = new StyleRange();
    style2.start = 11;
    style2.length = 13;
    style2.foreground = display.getSystemColor(SWT.COLOR_RED);
    text.setStyleRange(style2);
    // make NOPQRSTUVWXYZ have a blue background
    StyleRange style3 = new StyleRange();
    style3.start = 25;
    style3.length = 13;
    style3.background = display.getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(style3);
		 * */
	}
	
	public SqlSourceEditor() {
		logger.info("SessionInfo.getProjectInfo(): " + SessionInfo.getProjectInfo().toString());
		logger.info("SessionInfo.getTableInfo(): " + SessionInfo.getTableInfo().toString());
		
		setFileSeq(SessionInfo.getTableInfo().getFileSeq());
		
		tableInfos = TableDao.selectTableList(new TableVo(SessionInfo.getProjectInfo().getProjectName(), SessionInfo.getTableInfo().getFileSeq()));
//new DataBaseSyntaxLineStyler()		
	}
	
	


	public StyledText getStyledText() {
		return styledText;
	}

	public void setStyledText(StyledText styledText) {
		this.styledText = styledText;
	}

	public String getFileSeq() {
		return fileSeq;
	}

	public void setFileSeq(String fileSeq) {
		this.fileSeq = fileSeq;
	}
}
